/*************************************************
Author: byron
Date: 11/19/2013
Description:
Notes: 
*************************************************/

#ifndef __CManorBattleData_h__
#define __CManorBattleData_h__

#include "CTArray.h"
#include "commclass.h"
#include "../common/CRankArray.h"

class CManorBattleRole
{
public:
    CManorBattleRole()
    {
        Clear();
    }

    void Clear()
    {
        _iScore = 0;    //角色积分
        _iRoleHP = 0;   //角色血量
        _iEndTime = 0;  //结束时间
        _iSeriesKill = 0;  //连杀数
        _iReviveTimes = 0;   //金币复活次数
        _astPartnerHP.Clear();
    }

    virtual ~CManorBattleRole()
    {
    }

    int GetScore() const {return _iScore;}
    int GetRoleHP() const {return _iRoleHP;}
    int GetEndTime() const {return _iEndTime;}
    int GetSeriesKill() const {return _iSeriesKill;}
    int GetReviveTimes() const {return _iReviveTimes;}
    int GetPartnerHP(unsigned int uiPartnerID) 
    {
        for (int i = 0; i < _astPartnerHP.Size(); ++i)
        {
            if (_astPartnerHP[i]._uiKey == uiPartnerID)
            {
                return _astPartnerHP[i]._iValue;
            }
        }

        return 0;
    }

    void AddScore(int iVal){_iScore += iVal;}
    void SetRoleHP(int iVal){_iRoleHP = iVal;}
    void SetEndTime(int iVal){_iEndTime = iVal;}
    void AddSeriesKill(int iVal){_iSeriesKill += iVal;}
    void SetSeriesKill(int iVal){_iSeriesKill = iVal;}
    void SetReviveTimes(int iVal){_iReviveTimes = iVal;}
    void SetPartnerHP(unsigned int uiPartnerID, int iHP)
    {
        for (int i = 0; i < _astPartnerHP.Size(); ++i)
        {
            if (_astPartnerHP[i]._uiKey == uiPartnerID)
            {
                _astPartnerHP[i]._iValue = iHP;
                return;
            }
        }

        if (_astPartnerHP.Size() >= _astPartnerHP.GetCount())
        {
            for (int i = 0; i < _astPartnerHP.Size(); )//这里不递增
            {
                if (_astPartnerHP[i]._iValue <= 0)
                {
                    _astPartnerHP.DelOneItem(i);
                }
                else
                {
                    ++i;
                }
            }
        }

        CKeyValue stKeyValue;
        stKeyValue._uiKey = uiPartnerID;
        stKeyValue._iValue = iHP;
        _astPartnerHP.AddOneItem(stKeyValue);
    }

private:
    int     _iScore;    //角色积分
    int     _iRoleHP;   //角色血量
    int     _iEndTime;  //结束时间
    int     _iSeriesKill;  //连杀数
    int     _iReviveTimes;  //金币复活次数
    CTLib::CTArray<CKeyValue, MAX_PARTNER_ACT_COUNT> _astPartnerHP;  //伙伴血量
};

class CManorBattleDefUnit
{
public:
    CManorBattleDefUnit()
    {
        Clear();
    }

    void Clear()
    {
        _uiGID = 0;
        _iScore = 0;
        _iAcademy = 0;
        _sRoleName.Set("");
    }

    virtual ~CManorBattleDefUnit()
    {
    }

    int GetScore() const {return _iScore;}
    int GetAcademy() const {return _iAcademy;}
    unsigned int GetGID() const {return _uiGID;}
    char* GetRoleName() const {return _sRoleName.Get();}

    void SetScore(int iVal){_iScore = iVal;}
    void SetAcademy(int iVal){_iAcademy = iVal;}
    void SetGID(unsigned int uiVal){_uiGID = uiVal;}
    void SetRoleName(const char* pszName){_sRoleName.Set(pszName);}

private:
    int                 _iScore;     //攻击积分
    int                 _iAcademy;
    unsigned int        _uiGID;      //角色GID
    CTSizeString<ROLENAME_LEN>  _sRoleName; //角色名
};

class CManorBattleAtkUnit
{
public:
    CManorBattleAtkUnit()
    {
        Clear();
    }

    void Clear()
    {
        _uiGID = 0;
        _iScore = 0;
        _iAcademy = 0;
        _sRoleName.Set("");
    }

    virtual ~CManorBattleAtkUnit()
    {
    }

    int GetScore() const {return _iScore;}
    int GetAcademy() const {return _iAcademy;}
    unsigned int GetGID() const {return _uiGID;}
    char* GetRoleName() const {return _sRoleName.Get();}

    void SetScore(int iVal){_iScore = iVal;}
    void SetAcademy(int iVal){_iAcademy = iVal;}
    void SetGID(unsigned int uiVal){_uiGID = uiVal;}
    void SetRoleName(const char* pszName){_sRoleName.Set(pszName);}

private:
    int                 _iScore;     //攻击积分
    int                 _iAcademy;
    unsigned int        _uiGID;      //角色GID
    CTSizeString<ROLENAME_LEN>  _sRoleName; //角色名
};

class CManorBattleDefTag
{
public:
    CManorBattleDefTag()
    {
        Clear();
    }

    void Clear()
    {
        _uiGID = 0;
        _iScore = 0;
        _iLevel = 0;
        _iAcademy = 0;
        _sRoleName.Set("");
    }

    virtual ~CManorBattleDefTag()
    {
    }

    int GetScore() const {return _iScore;}
    int GetLevel() const {return _iLevel;}
    int GetAcademy() const {return _iAcademy;}
    unsigned int GetGID() const {return _uiGID;}
    char* GetRoleName() const {return _sRoleName.Get();}

    void SetScore(int iVal){_iScore = iVal;}
    void SetLevel(int iVal){_iLevel = iVal;}
    void SetAcademy(int iVal){_iAcademy = iVal;}
    void SetGID(unsigned int uiVal){_uiGID = uiVal;}
    void SetRoleName(const char* pszName){_sRoleName.Set(pszName);}

private:
    int                 _iScore;     //攻击积分
    int                 _iLevel;
    int                 _iAcademy;
    unsigned int        _uiGID;      //角色GID
    CTSizeString<ROLENAME_LEN>  _sRoleName; //角色名
};

class CManorBattleAtkTag
{
public:
    CManorBattleAtkTag()
    {
        Clear();
    }

    void Clear()
    {
        _uiGID = 0;
        _iScore = 0;
        _iLevel = 0;
        _iAcademy = 0;
        _sRoleName.Set("");
    }

    virtual ~CManorBattleAtkTag()
    {
    }

    int GetScore() const {return _iScore;}
    int GetLevel() const {return _iLevel;}
    int GetAcademy() const {return _iAcademy;}
    unsigned int GetGID() const {return _uiGID;}
    char* GetRoleName() const {return _sRoleName.Get();}

    void SetScore(int iVal){_iScore = iVal;}
    void SetLevel(int iVal){_iLevel = iVal;}
    void SetAcademy(int iVal){_iAcademy = iVal;}
    void SetGID(unsigned int uiVal){_uiGID = uiVal;}
    void SetRoleName(const char* pszName){_sRoleName.Set(pszName);}

private:
    int                 _iScore;     //攻击积分
    int                 _iLevel;
    int                 _iAcademy;
    unsigned int        _uiGID;      //角色GID
    CTSizeString<ROLENAME_LEN>  _sRoleName; //角色名
};

class CManorBattleClanUnit
{
public:
    CManorBattleClanUnit()
    {
        Clear();
    }

    void Clear()
    {
        _uiGID = 0;
        _iScore = 0;
        _iAcademy = 0;
        _sClanName.Set("");
    }

    virtual ~CManorBattleClanUnit()
    {
    }

    int GetScore() const {return _iScore;}
    int GetAcademy() const {return _iAcademy;}
    unsigned int GetGID() const {return _uiGID;}
    char* GetClanName() const {return _sClanName.Get();}

    void AddScore(int iVal){_iScore += iVal;}
    void SetScore(int iVal){_iScore = iVal;}
    void SetAcademy(int iVal){_iAcademy = iVal;}
    void SetGID(unsigned int uiVal){_uiGID = uiVal;}
    void SetClanName(const char* pszName){_sClanName.Set(pszName);}

private:
    int                 _iScore;     //攻击积分
    int                 _iAcademy;
    unsigned int        _uiGID;      //家族GID
    CTSizeString<CLAN_NAME_STRING_SIZE>  _sClanName; //家族昵称
};

class CManorBattleRank
{
public:
    CManorBattleRank()
    {
        Clear();
    }

    void Clear()
    {
        _astDefendRank.Clear();
        _astAttackRank.Clear();
        _astAttackClan.Clear();
        _astDefendList.Clear();
        _astAttackList.Clear();
    }

    virtual ~CManorBattleRank()
    {
    }

    bool IsDefendListGID(unsigned int uiGID)
    {
        for (int i = 0; i < _astDefendList.Size(); ++i)
        {
            if (_astDefendList[i].GetGID() == uiGID)
            {
                return true;
            }
        }
    
        return false;
    }
    bool IsAttackListGID(unsigned int uiGID)
    {
        for (int i = 0; i < _astAttackList.Size(); ++i)
        {
            if (_astAttackList[i].GetGID() == uiGID)
            {
                return true;
            }
        }
    
        return false;
    }

    int GetDefendSize() const {return _astDefendRank.Size();}
    int GetAttackSize() const {return _astAttackRank.Size();}
    int GetAttackClanSize() const {return _astAttackClan.Size();}
    int GetDefendListSize() const {return _astDefendList.Size();}
    int GetAttackListSize() const {return _astAttackList.Size();}

    CManorBattleDefUnit& GetDefendUnit(int iIndex)
    {
        return _astDefendRank[iIndex];
    }
    CManorBattleAtkUnit& GetAttackUnit(int iIndex)
    {
        return _astAttackRank[iIndex];
    }
    CManorBattleClanUnit& GetAttackClan(int iIndex)
    {
        return _astAttackClan[iIndex];
    }
    CManorBattleDefTag& GetDefendTag(int iIndex)
    {
        return _astDefendList[iIndex];
    }
    CManorBattleAtkTag& GetAttackTag(int iIndex)
    {
        return _astAttackList[iIndex];
    }

    int DefendRankUpdate(CManorBattleDefUnit& stUnit, int& iOld, int& iNew)
    {
        return _astDefendRank.Update(stUnit, iOld, iNew);
    }
    int AttackRankUpdate(CManorBattleAtkUnit& stUnit, int& iOld, int& iNew)
    {
        return _astAttackRank.Update(stUnit, iOld, iNew);
    }
    int AttackClanUpdate(CManorBattleClanUnit& stUnit, int& iOld, int& iNew)
    {
        return _astAttackClan.Update(stUnit, iOld, iNew);
    }
    int DefendTagUpdate(CManorBattleDefTag& stUnit, int& iOld, int& iNew)
    {
        return _astDefendList.Update(stUnit, iOld, iNew);
    }
    int AttackTagUpdate(CManorBattleAtkTag& stUnit, int& iOld, int& iNew)
    {
        return _astAttackList.Update(stUnit, iOld, iNew);
    }

    int DefendShiftDelOneItem(int iIndex)
    {
        return _astDefendList.ShiftDelOneItem(iIndex);
    }
    int AttackShiftDelOneItem(int iIndex)
    {
        return _astAttackList.ShiftDelOneItem(iIndex);
    }

private:
    CRankArray<CManorBattleDefUnit, MAX_MANOR_BATTLE_DEFEND_RANK>  _astDefendRank; //防守方积分排名
    CRankArray<CManorBattleAtkUnit, MAX_MANOR_BATTLE_ATTACK_RANK>  _astAttackRank; //攻击方积分排名
    CRankArray<CManorBattleClanUnit, MAX_MANOR_BATTLE_ATK_CLAN_RANK>  _astAttackClan; //攻击方家族积分排名
    CRankArray<CManorBattleDefTag, MAX_MANOR_BATTLE_DEFEND_LIST> _astDefendList;   //防守方目标列表
    CRankArray<CManorBattleAtkTag, MAX_MANOR_BATTLE_ATTACK_LIST> _astAttackList;   //进攻方目标列表
};

class CManorBattleMonUnit
{
public:
    CManorBattleMonUnit()
    {
        Clear();
    }

    void Clear()
    {
        _iHP = 0;       //当前血量
        _iMaxHP = 0;    //最大血量
        _iLevel = 0;    //世界等级
        _uiGroupID = 0; //怪物组ID
    }

    virtual ~CManorBattleMonUnit()
    {
    }

    int GetHP() const {return _iHP;}
    int GetMaxHP() const {return _iMaxHP;}
    int GetLevel() const {return _iLevel;}
    unsigned int GetGroupID() const {return _uiGroupID;}

    void SetHP(int iVal){_iHP = iVal;}
    void SetMaxHP(int iVal){_iMaxHP = iVal;}
    void SetLevel(int iVal){_iLevel = iVal;}
    void SetGroupID(unsigned int uiVal){_uiGroupID = uiVal;}

private:
    int     _iHP;   //当前血量
    int     _iMaxHP;    //最大血量
    int     _iLevel;    //世界等级
    unsigned int _uiGroupID; //怪物组ID
};

class CManorBattleMapUnit
{
public:
    CManorBattleMapUnit()
    {
        Clear();
    }

    void Clear()
    {
        _iAttackPosX = 0;   //攻击方坐标X
        _iAttackPosY = 0;   //攻击方坐标Y
        _iDefendPosX = 0;   //防守方坐标X
        _iDefendPosY = 0;   //防守方坐标Y
        _iBlessStatus = 0;  //护佑状态ID
        _uiMapID = 0;   //场景地图ID
    }

    virtual ~CManorBattleMapUnit()
    {
    }

    int GetAttackPosX() const {return _iAttackPosX;}
    int GetAttackPosY() const {return _iAttackPosY;}
    int GetDefendPosX() const {return _iDefendPosX;}
    int GetDefendPosY() const {return _iDefendPosY;}
    int GetBlessStatus() const {return _iBlessStatus;}
    unsigned int GetMapID() const {return _uiMapID;}

    void SetAttackPosX(int iVal){_iAttackPosX = iVal;}
    void SetAttackPosY(int iVal){_iAttackPosY = iVal;}
    void SetDefendPosX(int iVal){_iDefendPosX = iVal;}
    void SetDefendPosY(int iVal){_iDefendPosY = iVal;}
    void SetBlessStatus(int iVal){_iBlessStatus = iVal;}
    void SetMapID(unsigned int uiVal){_uiMapID = uiVal;}

private:
    int     _iAttackPosX;
    int     _iAttackPosY;
    int     _iDefendPosX;
    int     _iDefendPosY;
    int     _iBlessStatus;
    unsigned int _uiMapID;
};

class CManorBattleData
{
public:
    CManorBattleData()
    {
        Clear();
    }

    void Clear()
    {
        _iBattleStat = 0;
        _iStatEndTime = 0;
        _iBombStatus = 0;
        _iBombLevel = 0;
        _iDefendRoleNum = 0;
        _iAttackRoleNum = 0;
        _astMapList.Clear();
        _astClanList.Clear();
        _astMonsterList.Clear();
    }

    virtual ~CManorBattleData()
    {
    }

    int GetBattleStat() const {return _iBattleStat;}
    int GetStatEndTime() const {return _iStatEndTime;}
    int GetBombStatus() const {return _iBombStatus;}
    int GetBombLevel() const {return _iBombLevel;}
    int GetDefendRoleNum() const {return _iDefendRoleNum;}
    int GetAttackRoleNum() const {return _iAttackRoleNum;}
    int GetMapSize() const {return _astMapList.Size();}
    int GetClanSize() const {return _astClanList.Size();}
    int GetMonSize() const {return _astMonsterList.Size();}

    CManorBattleMapUnit& GetMap(int iIndex)
    {
        return _astMapList[iIndex];
    }

    int FindClan(unsigned int uiClanID)
    {
        for (int i = 0; i < _astClanList.Size(); ++i)
        {
            if (_astClanList[i].GetGID() == uiClanID)
            {
                return i;
            }
        }
    
        return -1;
    }

    CManorBattleClanUnit& GetClan(int iIndex)
    {
        return _astClanList[iIndex];
    }

    CManorBattleMonUnit& GetMonster(int iIndex)
    {
        return _astMonsterList[iIndex];
    }

    void SetBattleStat(int iVal) {_iBattleStat = iVal;}
    void SetStatEndTime(int iVal) {_iStatEndTime = iVal;}
    void SetBombStatus(int iVal) {_iBombStatus = iVal;}
    void SetBombLevel(int iVal) {_iBombLevel = iVal;}

    void AddDefendRoleNum(int iVal) {_iDefendRoleNum += iVal;}
    void AddAttackRoleNum(int iVal) {_iAttackRoleNum += iVal;}

    void AddMap(CManorBattleMapUnit& stUnit)
    {
        _astMapList.AddOneItem(stUnit);
    }

    void AddClan(CManorBattleClanUnit& stUnit)
    {
        _astClanList.AddOneItem(stUnit);
    }

    void AddMonster(CManorBattleMonUnit& stUnit)
    {
        _astMonsterList.AddOneItem(stUnit);
    }

    int GetClanCamp(unsigned int uiClanID)
    {
        for (int i = 0; i < _astClanList.Size(); ++i)
        {
            if (_astClanList[i].GetGID() == uiClanID)
            {
                if (i == 0) //约定0元素是防守家族
                {
                    return ENM_MANOR_BATTLE_CAMP_DEFEND;
                }
                else
                {
                    return ENM_MANOR_BATTLE_CAMP_ATTACK;
                }
            }
        }
    
        return ENM_MANOR_BATTLE_CAMP_NONE;
    }

private:
    int     _iBattleStat;  //战斗阶段 0 -- 黑铁之堡 1 -- 白银之角 2 -- 黄金之城
    int     _iStatEndTime; //阶段结束时间
    int     _iBombStatus;  //飞火流星状态ID
    int     _iBombLevel;   //飞火流星等级
    int     _iDefendRoleNum;
    int     _iAttackRoleNum;
    CTLib::CTArray<CManorBattleMapUnit, MAX_MANOR_BATTLE_SCENE_COUNT> _astMapList;
    CTLib::CTArray<CManorBattleClanUnit, MAX_MANOR_BATTLE_ACT_CLAN_COUNT> _astClanList;
    CTLib::CTArray<CManorBattleMonUnit, MAX_MANOR_BATTLE_MONSTER_COUNT> _astMonsterList;
};

#endif //__CManorBattleData_h__

